home *** CD-ROM | disk | FTP | other *** search
/ Apple Developer Connection 1998 Fall: Game Toolkit / Disc.iso / SDKs / Apple Game Sprockets / InputSprocket / Sample Drivers / Common Driver Code / DialogUtils.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-07-17  |  11.4 KB  |  315 lines  |  [TEXT/CWIE]

  1. /*************************************************************************************
  2.  
  3. File:      DialogUtils.h
  4.  
  5. Copyright © 1996, 1997, 1998 Apple Computer, Inc., All Rights Reserved
  6.  
  7.  
  8. You may incorporate this sample code into your applications without
  9. restriction, though the sample code has been provided "AS IS" and the
  10. responsibility for its operation is 100% yours.  However, what you are
  11. not permitted to do is to redistribute the source as "DSC Sample Code"
  12. after having made changes. If you're going to re-distribute the source,
  13. we require that you make it clear in the source that the code was
  14. descended from Apple Sample Code, but that you've made changes.
  15.  
  16. *************************************************************************************/
  17.  
  18. #ifndef __DIALOGUTILS__
  19. #define __DIALOGUTILS__
  20.  
  21. #ifndef __DIALOGS__
  22. #include <Dialogs.h>
  23. #endif
  24.  
  25. #ifndef __MENUS__
  26. #include <Menus.h>
  27. #endif
  28.  
  29. #ifndef __QUICKDRAW__
  30. #include <Quickdraw.h>
  31. #endif
  32.  
  33. #ifndef __MACTYPES__
  34. #include <MacTypes.h>
  35. #endif
  36.  
  37. #ifndef __ICONS__
  38. #include <Icons.h>
  39. #endif
  40.  
  41. #ifndef __QDOFFSCREEN__
  42. #include <QDOffscreen.h>
  43. #endif
  44.  
  45. #ifndef __PALETTES__
  46. #include <Palettes.h>
  47. #endif
  48.  
  49. #ifdef __cplusplus
  50. extern "C" {
  51. #endif
  52.  
  53. /***** TYPES ***********************************************************************************************/
  54. #pragma mark Types
  55.  
  56. //typedef SInt16 DialogItem;
  57. /*typedef SInt16 DialogItemType;*/    // this definition is in the new Universal Headers
  58. typedef SInt16 ControlValue;
  59.  
  60. /***** ENUMS ***********************************************************************************************/
  61. typedef enum { kGSActive = true, kGSInactive = false } GScActiveType;
  62.  
  63. typedef enum
  64. {
  65.     GScRampW =   0,    // 0xffff
  66.     GScRamp1 =   1,    // 0xeeee
  67.     GScRamp2 =   2,    // 0xddd        (background color of dialog)
  68.     GScRamp3 =   3,    // 0xcccc
  69.     GScRamp4 =   4,    // 0xbbbb
  70.     GScRamp5 =   5,    // 0xaaaa
  71.     GScRamp6 =   6,    // 0x9999
  72.     GScRamp7 =   7,    // 0x8888
  73.     GScRamp8 =   8,    // 0x7777
  74.     GScRamp9 =   9,    // 0x6666
  75.     GScRamp10 = 10,    // 0x5555
  76.     GScRamp11 = 11,    // 0x4444
  77.     GScRamp12 = 12,    // 0x3333
  78.     GScRampA1 = 13,    // 0x2222
  79.     GScRampA2 = 14,    // 0x1111
  80.     GScRampB  = 15,    // 0x0000
  81.     
  82.     GScRampWhite    = GScRampW,
  83.     GScRampBlack    = GScRampB,
  84.     GScRampBG        = GScRamp2        // this should be the background color of the dialog    
  85. } GScGrayRamp;
  86.  
  87. /***** C Functions ***********************************************************************************************/
  88. #pragma mark C Functions
  89.  
  90. void            DialogItem_SetUserProc(DialogRef inDialog, DialogItemIndex inItem, const UserItemUPP inUserProc);
  91. void            DialogItem_SetOKUserProc(DialogRef inDialog, DialogItemIndex inItem);
  92. void            DialogItem_SetPrimaryGroupUserProc(DialogRef inDialog, DialogItemIndex inItem);
  93. void            DialogItem_SetSecondaryGroupUserProc(DialogRef inDialog, DialogItemIndex inItem);
  94.  
  95. ControlHandle    DialogItem_GetControl(DialogRef inDialog, DialogItemIndex inItem);
  96. void            DialogItem_HiliteControl(DialogRef inDialog, DialogItemIndex inItem, ControlPartCode hiliteState);
  97. void            DialogItem_AnimateButtonClick(DialogRef inDialog, DialogItemIndex inItem);
  98.  
  99. // popup menu helper routines
  100. MenuHandle        DialogItem_GetPopupMenu(DialogRef inDialog, DialogItemIndex inItem);
  101. void            DialogItem_SetPopupMenu(DialogRef inDialog, DialogItemIndex inItem, MenuHandle inMenuHandle);
  102.  
  103. // enable/disable dialog item
  104. void            DialogItem_Enable(DialogRef inDialog, DialogItemIndex inItem);
  105. void            DialogItem_Disable(DialogRef inDialog, DialogItemIndex inItem);
  106.  
  107. // get/set text
  108. void            DialogItem_GetText(DialogRef inDialog, DialogItemIndex inItem, Str255 outText);
  109. void            DialogItem_SetText(DialogRef inDialog, DialogItemIndex inItem, const StringPtr inText);
  110. void            DialogItem_SetTextQuietly(DialogRef inDialog, DialogItemIndex inItem, const StringPtr inText);
  111.  
  112. // radio button functions
  113. void            DialogItem_SetRadioButtonGroup(DialogRef inDialog, DialogItemIndex inFirstItem, DialogItemIndex inLastItem, DialogItemIndex inNewItem);
  114. DialogItemIndex        DialogItem_GetRadioButtonGroup(DialogRef inDialog, DialogItemIndex inFirstItem, DialogItemIndex inLastItem);
  115.  
  116. // min,max and value get and set routines
  117. ControlValue    DialogItem_GetValue(DialogRef inDialog, DialogItemIndex inItem);
  118. ControlValue    DialogItem_GetMin(DialogRef inDialog, DialogItemIndex inItem);
  119. ControlValue    DialogItem_GetMax(DialogRef inDialog, DialogItemIndex inItem);
  120.  
  121. void            DialogItem_SetValue(DialogRef inDialog, DialogItemIndex inItem, ControlValue value);
  122. void            DialogItem_SetMin(DialogRef inDialog, DialogItemIndex inItem, ControlValue min);
  123. void            DialogItem_SetMax(DialogRef inDialog, DialogItemIndex inItem, ControlValue max);
  124.  
  125. void            DialogItem_SetValueQuietly(DialogRef inDialog, DialogItemIndex inItem, ControlValue value);
  126.  
  127. // get,set item rectangle
  128. void             DialogItem_GetRect(DialogRef inDialog, DialogItemIndex inItem, Rect *outItemRect);
  129. void             DialogItem_SetRect(DialogRef inDialog, DialogItemIndex inItem, const Rect *inItemRect);
  130.  
  131. void            DialogItem_DeltaRect(DialogRef inDialog, DialogItemIndex inItem, short inDeltaTop, short inDeltaLeft, short inDeltaBottom, short inDeltaRight);
  132. void            DialogItem_OffsetRect(DialogRef inDialog, DialogItemIndex inItem, short inDeltaH, short inDeltaV);
  133. short            DialogItem_GetWidth(DialogRef inDialog, DialogItemIndex inItem);
  134.  
  135. // validate/invalidate (i.e. updates/drawing)
  136. void            DialogItem_Invalidate(DialogRef inDialog, DialogItemIndex inItem);
  137. void             DialogItem_Valididate(DialogRef inDialog, DialogItemIndex inItem);
  138.  
  139. // show/hide
  140. void            DialogItem_Show(DialogRef inDialog, DialogItemIndex inItem);
  141. void            DialogItem_Hide(DialogRef inDialog, DialogItemIndex inItem);
  142.  
  143. // getting and setting the type
  144. DialogItemType    DialogItem_GetType(DialogRef inDialog, DialogItemIndex inItem);
  145. void            DialogItem_SetType(DialogRef inDialog, DialogItemIndex inItem, DialogItemType inType);
  146.  
  147. // getting and setting the default item
  148. DialogItemIndex        Dialog_GetDefaultItem(DialogRef inDialog);
  149. DialogItemIndex        Dialog_GetCancelItem(DialogRef inDialog);
  150.  
  151. void            Dialog_SetDefaultItem(DialogRef inDialog, DialogItemIndex inItem);
  152. void            Dialog_SetCancelItem(DialogRef inDialog, DialogItemIndex inItem);
  153. void            Dialog_SetTracksCursor(DialogRef inDialog, Boolean tracks);
  154.  
  155. /**** validates/invalidates the whole window ****/
  156. void            Window_Invalidate(WindowRef inWindow);
  157. void            Window_Validate(WindowRef inWindow);
  158.  
  159. /**** FilterKeyEvent (ok/cancel fitering for keyDown events) (set default/cancel item first) */
  160. Boolean            FilterKeyEvent(DialogPtr inDialog, EventRecord *inEvent, DialogItemIndex *outItem);
  161.  
  162. /**** KeyEventOK and KeyEventCancel */
  163. Boolean            KeyEventOK(EventRecord *inEvent);
  164. Boolean            KeyEventCancel(EventRecord *inEvent);
  165.  
  166. /**** Modern Standard FilterProc (ok/cancel hiliting/enabling & accepts ok/cancel key presses) */
  167. extern ModalFilterUPP ModernStdFilterProcUPP;
  168. pascal Boolean ModernStdFilterProc(DialogPtr inDialog, EventRecord *inEvent, DialogItemIndex *outItem);
  169.  
  170. /**** GetKeyModifiers returns current modifier state */
  171. EventModifiers GetKeyModifiers(void);
  172.  
  173. /**** Simplified CopyBits functions (no more port or color concerns) */ 
  174. void    CopyBitsLite(CGrafPtr src, CGrafPtr dst, const Rect *srcRect, const Rect *dstRect);
  175. void     CopyBitsLiteWithColor(CGrafPtr src, CGrafPtr dst, const Rect *srcRect, const Rect *dstRect, const RGBColor *inColor);
  176.  
  177. /**** Grayscale Functions */
  178. void    GScForeColor_Set(GScGrayRamp color);
  179. void    GScBackColor_Set(GScGrayRamp color);
  180.  
  181. void    GScTopLeft_Draw(const Rect *r, GScGrayRamp color);        // draws the top left of a rect w/o corners
  182. void    GScBotRight_Draw(const Rect *r, GScGrayRamp color);        // draws the bot right of a rec w/o corners
  183.  
  184. void    GScGroupBox_PrimarySimple_Draw(const Rect *r, GScActiveType active);
  185. void    GScGroupBox_SecondarySimple_Draw(const Rect *r, GScActiveType active);
  186.  
  187. void    GScGroupBox_PrimaryNamed_Draw(const Rect *r, const Str255 string, GScActiveType active);
  188. void    GScGroupBox_SecondaryNamed_Draw(const Rect *r, const Str255 string, GScActiveType active);
  189.  
  190. void    GScTextEntryFrame_Draw(const Rect *r, GScActiveType active);
  191.  
  192. #ifdef __cplusplus
  193. }
  194. #endif
  195.  
  196.  
  197. #pragma mark C++ Functions
  198.  
  199. #ifdef __cplusplus
  200. class    QDColorState
  201. {
  202. public:
  203.     QDColorState();
  204.     ~QDColorState();                
  205.  
  206.     static void    Clear();
  207.  
  208. private:
  209.     ColorSpec    mForegroundColor;
  210.     ColorSpec    mBackgroundColor;
  211. };
  212.  
  213. class    QDTextState
  214. {
  215. public:
  216.     QDTextState();
  217.     ~QDTextState();
  218.                 
  219.     static void    Clear();
  220.  
  221. private:
  222.     SInt16        mFontID;
  223.     SInt16        mFace;
  224.     SInt16        mMode;
  225.     SInt16        mSize;
  226. };
  227.  
  228. class QDPenState
  229. {
  230. public:
  231.     QDPenState();
  232.     ~QDPenState();
  233.     
  234.     static void Clear();
  235.     
  236. private:
  237.     PenState    mPenState;
  238. };
  239.  
  240. class    GWorldState 
  241. {
  242. public:
  243.     GWorldState(void);
  244.     GWorldState(GrafPtr inNewPort);    // sets the port to inNewPort
  245.     
  246.     ~GWorldState(void);
  247.                 
  248. private:
  249.     CGrafPtr    mPort;
  250.     GDHandle    mGDH;
  251. };
  252. #endif /* __cplusplus */
  253.  
  254.  
  255. /*
  256.  *
  257.  * Stackbased classes for saving/restoring graphics 
  258.  *
  259.  */
  260.  
  261. /***** MACROS ***********************************************************************************************/
  262. #pragma mark Macros
  263.  
  264. #ifdef __cplusplus
  265. // QuickDraw shortcut
  266. inline Boolean isColorPort(GrafPtr p)                    { return ((((GrafPtr)p)->portBits.rowBytes & 0xC000) == 0xC000); }
  267.  
  268. // WindowManager shortcut
  269. inline Boolean isDialogWindow(WindowRef w)                 { return (kDialogWindowKind         == GetWindowKind(w)); }
  270.  
  271. // DialogManager type shortcuts
  272. inline Boolean isUserType(DialogItemType t)                { return ((t & ~kItemDisableBit)     == userItem); }
  273.  
  274. inline Boolean isControlType(DialogItemType t)            { return ((t & kControlDialogItem)    == kControlDialogItem); }
  275. inline Boolean isButtonType(DialogItemType t)            { return ((t & ~kItemDisableBit)     == kButtonDialogItem); }
  276. inline Boolean isCheckBoxType(DialogItemType t)            { return ((t & ~kItemDisableBit)     == kCheckBoxDialogItem); }
  277. inline Boolean isRadioButtonType(DialogItemType t)        { return ((t & ~kItemDisableBit)     == kRadioButtonDialogItem); }
  278. inline Boolean isResourceControlType(DialogItemType t)    { return ((t & ~kItemDisableBit)     == kResourceControlDialogItem); }
  279.  
  280. inline Boolean isStaticTextType(DialogItemType t)        { return ((t & ~kItemDisableBit)     == kStaticTextDialogItem); }
  281. inline Boolean isEditTextType(DialogItemType t)            { return ((t & ~kItemDisableBit)     == kEditTextDialogItem); }
  282.  
  283. inline Boolean isIconType(DialogItemType t)                { return ((t & kIconDialogItem)     == kIconDialogItem); }
  284. inline Boolean isPictureType(DialogItemType t)            { return ((t & kPictureDialogItem)     == kPictureDialogItem); }
  285.  
  286. inline Boolean isDisabledType(DialogItemType t)            { return ((t & kItemDisableBit)     == kItemDisableBit); }
  287. inline Boolean isEnabledType(DialogItemType t)            { return ((t & kItemDisableBit)     == 0); }
  288. #else
  289. // QuickDraw shortcut
  290. #define    isColorPort(p)                ((((GrafPtr)p)->portBits.rowBytes & 0xC000) == 0xC000)
  291.  
  292. // window manager shortcut
  293. #define isDialogWindow(w)             (kDialogWindowKind         == GetWindowKind(w))
  294.  
  295. // type shortcuts
  296. #define isUserType(t)                ((t & ~kItemDisableBit) == userItem)
  297.  
  298. #define isControlType(t)            ((t & kControlDialogItem)    == kControlDialogItem)
  299. #define isButtonType(t)                ((t & ~kItemDisableBit)     == kButtonDialogItem)
  300. #define isCheckBoxType(t)            ((t & ~kItemDisableBit)     == kCheckBoxDialogItem)
  301. #define isRadioButtonType(t)        ((t & ~kItemDisableBit)     == kRadioButtonDialogItem)
  302. #define isResourceControlType(t)    ((t & ~kItemDisableBit)     == kResourceControlDialogItem)
  303.  
  304. #define isStaticTextType(t)            ((t & ~kItemDisableBit)     == kStaticTextDialogItem)
  305. #define isEditTextType(t)            ((t & ~kItemDisableBit)     == kEditTextDialogItem)
  306.  
  307. #define isIconType(t)                ((t & kIconDialogItem)         == kIconDialogItem)
  308. #define isPictureType(t)            ((t & kPictureDialogItem)     == kPictureDialogItem)
  309.  
  310. #define isDisabledType(t)            ((t & kItemDisableBit)         == kItemDisableBit)
  311. #define isEnabledType(t)            ((t & kItemDisableBit)         == 0)
  312. #endif
  313.  
  314. #endif __ISPDIALOGUTILS__
  315.